const fs = require('fs');
const path = require('path');
const { htmlToDocx, docxToBuffer } = require('../dist/umd/index.umd.js');

describe('直接颜色继承测试', () => {
  it('应该能够将用户的HTML文件转换为DOCX并保持颜色样式', async () => {
    try {
      // 读取用户的测试HTML文件
      const htmlPath = path.join(__dirname, '../server/test.html');
      const htmlContent = fs.readFileSync(htmlPath, 'utf8');

      console.log('读取HTML文件成功，内容如下：');
      console.log(htmlContent.substring(0, 200) + '...'); // 只显示部分内容

      console.log('\n开始转换HTML到DOCX...');
      const { document, warnings } = await htmlToDocx(htmlContent);

      console.log('转换DOCX到Buffer...');
      const buffer = await docxToBuffer(document);

      // 保存转换后的文件
      const outputPath = path.join(__dirname, '../test/output-color-test.docx');
      fs.writeFileSync(outputPath, buffer);

      console.log(`\n转换成功！文件已保存到: ${outputPath}`);
      console.log('请打开此文件检查文字是否显示为红色。');

      if (warnings.length > 0) {
        console.log('\n转换警告:', warnings);
      }

      // 验证转换成功
      expect(buffer).toBeInstanceOf(Buffer);
      expect(buffer.length).toBeGreaterThan(0);
    } catch (error) {
      console.error('转换失败:', error);
      throw error;
    }
  }, 30000); // 增加超时时间到30秒
});
